package com.shababeach.travel.service.impl;

import com.shababeach.travel.entity.LocationType;
import com.shababeach.travel.repository.LocationTypeRepository;
import com.shababeach.travel.service.LocationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 位置类型Service实现类
 */
@Service
public class LocationTypeServiceImpl implements LocationTypeService {

    @Autowired
    private LocationTypeRepository locationTypeRepository;

    // 开启状态
    private final static Integer StatusEnabled = 1;
    private final static Integer StatusClose = 0;

    /**
     * 获取所有启用的分类
     */
    @Override
    public List<LocationType> getEnabledTypes() {
        return locationTypeRepository.findByStatus(StatusEnabled);
    }

    @Override
    public LocationType getById(Integer id) {
        Optional<LocationType> locationType = locationTypeRepository.findById(id);
        return locationType.orElse(null);
    }

    @Override
    public Page<LocationType> page(Pageable pageable, String name) {
        return locationTypeRepository.findByName(name, pageable);
    }

    @Override
    public Page<LocationType> page(Pageable pageable) {
        return locationTypeRepository.findAll(pageable);
    }
} 